<template>
  <view>
    <uni-section title="自定义校验规则" type="line">
      <view class="example">
        <!-- 自定义表单校验 -->
        <uni-forms ref="customForm" :modelValue="customFormData" label-position="top">
          <uni-forms-item label=" 姓名"  name="name">
            <uni-easyinput v-model="customFormData.username" placeholder="请输入姓名" />
          </uni-forms-item>
          <uni-forms-item label=" 年龄"  name="age">
            <uni-easyinput v-model="customFormData.password" placeholder="请输入年龄" />
          </uni-forms-item>
        </uni-forms>
        <button type="primary" @click="submit()">提交</button>
      </view>
    </uni-section>
  </view>
</template>

<script setup lang="ts">
import { ref,reactive } from 'vue'

const customForm = ref(null);

const customFormData  = reactive({
  username: '',
  password: '',
  hobby: []
})

const submit = () => {
/*  customForm.value.validate((valid: boolean) => {
    if (valid) {
      uni.showToast({
        title: '校验通过',
        icon: 'success'
      })
    } else {
      uni.showToast({
        title: '校验失败',
        icon: 'none'
      })
    }
  })*/
  uni.request({
    url: 'http://localhost:48080/admin-api/system/auth/login',
    data: customFormData,
    method: 'POST',
    success: (res) => {
      console.log(res)

      uni.switchTab({
        url: '/pages/index/index'
      })

    }
  })
}
</script>


<style scoped lang="scss">

</style>
